﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace LogNet6;
public static class LoggerServiceExtension
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="builder"></param>
    /// <returns></returns>
    public static ILoggingBuilder AddNet6Logger(this ILoggingBuilder builder)
    {
        builder.Services.TryAddSingleton<ILoggerProvider, LoggerProvider>();
        return builder;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="builder"></param>
    /// <param name="logLevelSection"></param>
    /// <example>IConfiguration.GetSection("Logging:LogLevel")</example>
    /// <returns></returns>
    public static ILoggingBuilder AddNet6LoggerFilter(this ILoggingBuilder builder, IConfigurationSection logLevelSection)
    {
        foreach (var item in logLevelSection.GetChildren())
            builder.AddFilter(item.Key, item.Get<LogLevel>());
        return builder;
    }


}

